﻿using System;
using System.Linq;
using Myotragus.Data.Criteria;
using Myotragus.Data.Metadata;
using Myotragus.Data.Util;
using Myotragus.Store.Model.Tests.Domain;
using NUnit.Framework;

namespace Myotragus.Store.Model.Tests
{
  [TestFixture]
  public class LocalizableTypeDescriptorFixture
  {
    static readonly Type TypeOfILocalizableObject = typeof(ILocalizableObject);

    [SetUp]
    public void SetUp()
    {
      FixtureHelper.InitializeServices();
      FixtureHelper.InitializeEntities(new []{TypeOfILocalizableObject});
    }

    [Test]
    public void GetDescriptor()
    {
      var descriptor = FixtureHelper.Container
        .Resolve<IEntityDescriptor<ILocalizableObject>>();

      Assert.AreEqual(descriptor.EntityProperties.Count, 
        ReflectionHelper.GetProperties(typeof(ILocalizableObject)).Count());
    }

    [Test]
    public void LocalizableDescriptor()
    {
      var localizable = FixtureHelper.Container
        .Resolve<ILocalizableEntityDescriptor<ILocalizableObject>>();

      var count = ReflectionHelper.GetProperties(typeof(ILocalizableObject)).Count() ;

      Assert.AreEqual(count, localizable.EntityProperties.Count);
      Assert.GreaterOrEqual(localizable.LoadEntityProperties.Count, count);
      Assert.GreaterOrEqual(localizable.SaveEntityProperties.Count, count);
    }

    [Test]
    public void DefaultsLocalizableDescriptor()
    {
      var localizable = FixtureHelper.Container
        .Resolve<IDefaultsLocalizableEntityDescriptor<ILocalizableObject>>();

      var count = ReflectionHelper.GetProperties(typeof(ILocalizableObject)).Count();

      Assert.AreEqual(count, localizable.EntityProperties.Count);
      Assert.GreaterOrEqual(localizable.LoadEntityProperties.Count, count);
      Assert.GreaterOrEqual(localizable.SaveEntityProperties.Count, count);
    }
  }
}
